package com.dtw.ditouwang.ui.main;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.RadioGroup;

import com.dtw.ditouwang.R;
import com.dtw.ditouwang.ui.BaseActivity;
import com.dtw.ditouwang.ui.home.HomeFragment;
import com.dtw.ditouwang.ui.mine.MineFragment;
import com.dtw.ditouwang.ui.more.MoreFragment;
import com.dtw.ditouwang.ui.movement.MovementFragment;

import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;

public class MainActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener {


    //<editor-fold desc="控件">
    private RadioGroup radiogroup;
    //</editor-fold>

    Fragment homeFragment,movementFragment,moreFragment,mineFragment;
    long lastClickTime=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        homeFragment=new HomeFragment();
        movementFragment=new MovementFragment();
        moreFragment=new MoreFragment();
        mineFragment=new MineFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.framelayout, homeFragment).commit();

        homeFragment.setUserVisibleHint(false);
    }

    private void initView() {
        radiogroup = findViewById(R.id.radiogroup);
        radiogroup.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId){
            case R.id.radio_home:
                getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,homeFragment).commit();
            break;
            case R.id.radio_movement:
                getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,movementFragment).commit();
            break;
            case R.id.radio_more:
                getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,moreFragment).commit();
            break;
            case R.id.radio_mine:
                getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,mineFragment).commit();
            break;
        }
    }

    @Override
    public void onBackPressed() {
        if(System.currentTimeMillis()-lastClickTime<500){
            finish();
        }else{
            lastClickTime=System.currentTimeMillis();
            showToast("再按一次返回退出");
        }
    }
}
